define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'roomcardcode/clubroom/index',
                    table: 'v_annal_room',
                }
            });

            var table = $("#table");

          table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'createtime',
                sortName: 'createtime',
                search: false,
                columns: [
                    [
                     	{field: 'clubname', title: __('Clubname'),searchable:false},
						{field: 'clubId', title: __('ClubId')},
						{field: 'nickname', title: __('Nickname'),searchable:false},
						{field: 'uid', title: __('Uid'),searchable:false},
						{field: 'clubtype', title: __('Clubtype'),searchable:false},
                     	{field: 'kinId', title: __('KinId'), searchList: $.getJSON('ajax/getOnGameList?type=1'), style: 'min-width:100px;'},
                        {field: 'roomid', title: __('Roomid')},
                        {field: 'win', title: __('Win'),searchable:false},
                        {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetimes, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD HH:mm:ss"', style: 'min-width:90px;'},
                        {field: 'paytypename', title: __('Paytype'),searchable:false},
                        {field: 'roomcode', title: __('Roomcode'),searchable:false},
                        {field: 'diamond', title: __('俱乐部房卡余额'),searchable:false},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {'disbanded': __('解散'), 'ydisbanded': __('强制解散'),'gameover':__('游戏结束')}, style: 'min-width:100px;'},
                    ]
                ],
                
                onLoadSuccess: function (data) {
					$("#statistics").html(
							'<a class="btn btn-danger">俱乐部房卡总消耗：' + data.statistics.roomcodenum + '</a>&nbsp;' 
							+ '<a class="btn btn-success">俱乐部总房间数：' + data.statistics.room_num + '</a>&nbsp;' 
							+ '<a class="btn btn-info">俱乐部房间总时长：' + data.statistics.time_count + '</a>&nbsp;' 
							+ '<a class="btn btn-warning">俱乐部平均房间时长：' + data.statistics.time_avg + '</a>&nbsp;' 
							);
                	$("#statistics").show();
                }
                
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});